import java.util.ArrayList;
import junit.framework.TestCase;

public class HandTest extends TestCase {

	public HandTest(String testName) {
		super(testName);
	}

	protected void setUp() throws Exception {
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	/*
	 * Test of ustalUkladPokera method, of class Hand.
	 */
	public void testUstalUkladPokera() { // 5 kolejnych kart w jednym kolorze
		System.out.println("ustalUkladPokera test begins");

		Card f2 = fabrykaKartyPik(Rank.r2);
		Card f3 = fabrykaKartyPik(Rank.r3);
		Card f4 = fabrykaKartyPik(Rank.r4);
		Card f5 = fabrykaKartyPik(Rank.r5);
		Card f6 = fabrykaKartyPik(Rank.r6);

		ArrayList<Card> karty = dodajKartyDoListy(f2, f3, f4, f5, f6);

		Hand instance = new Hand(karty);

		String expectedResult = "Uklad: Straight_Flush";
		String result = "Uklad: " + (instance.pickSet());
		assertEquals(expectedResult, result);

		System.out.println("ustalUkladPokera test finished succesfully");
	}

	/*
	 * Test of ustalUkladKarety method, of class Hand.
	 */
	public void testUstalUKladKarety() {
		System.out.println("ustalUkladKarety test begins");

		Card as_1 = fabrykaKartyPik(Rank.ace);
		Card as_2 = fabrykaKartyTrefl(Rank.ace);
		Card as_3 = fabrykaKartyKaro(Rank.ace);
		Card as_4 = fabrykaKartyKier(Rank.ace);
		Card dama = fabrykaKartyTrefl(Rank.queen);

		ArrayList<Card> karty = dodajKartyDoListy(as_1, as_2, as_3, as_4, dama);

		Hand instance = new Hand(karty);

		String expectedResult = "Uklad: Four_Of_A_Kind";
		String result = "Uklad: " + (instance.pickSet());
		assertEquals(expectedResult, result);

		System.out.println("ustalUkladKarety test finished succesfully");
	}

	/*
	 * Test of ustalUkladFula method, of class Hand.
	 */
	public void testUstalUKladFula() {
		System.out.println("ustalUkladFula test begins");

		Card as_1 = fabrykaKartyPik(Rank.ace);
		Card as_2 = fabrykaKartyKier(Rank.ace);
		Card as_3 = fabrykaKartyTrefl(Rank.ace);
		Card f5 = fabrykaKartyKaro(Rank.r5);
		Card f5_2 = fabrykaKartyPik(Rank.r5);

		ArrayList<Card> karty = dodajKartyDoListy(as_1, as_2, as_3, f5, f5_2);

		Hand instance = new Hand(karty);

		String expectedResult = "Uklad: Full_House";
		String result = "Uklad: " + (instance.pickSet());
		assertEquals(expectedResult, result);

		System.out.println("ustalUkladFula test finished succesfully");
	}

	/*
	 * Test of ustalUkladKoloru method, of class Hand.
	 */
	public void testUstalUKladKoloru() {
		System.out.println("ustalUkladKoloru test begins");

		Card as = fabrykaKartyPik(Rank.ace);
		Card krol = fabrykaKartyPik(Rank.king);
		Card f4 = fabrykaKartyPik(Rank.r4);
		Card f5 = fabrykaKartyPik(Rank.r5);
		Card dama = fabrykaKartyPik(Rank.queen);

		ArrayList<Card> karty = dodajKartyDoListy(as, krol, f4, f5, dama);

		Hand instance = new Hand(karty);

		String expectedResult = "Uklad: Flush";
		String result = "Uklad: " + (instance.pickSet());
		assertEquals(expectedResult, result);

		System.out.println("ustalUkladKoloru test finished succesfully");
	}

	/*
	 * Test of ustalUkladStrita method, of class Hand.
	 */
	public void testUstalUKladStrita() {
		System.out.println("ustalUkladStrita test begins");

		Card f2 = fabrykaKartyPik(Rank.r2);
		Card f3 = fabrykaKartyTrefl(Rank.r3);
		Card f4 = fabrykaKartyKier(Rank.r4);
		Card f5 = fabrykaKartyPik(Rank.r5);
		Card f6 = fabrykaKartyKaro(Rank.r6);

		ArrayList<Card> karty = dodajKartyDoListy(f2, f3, f4, f5, f6);

		Hand instance = new Hand(karty);

		String expectedResult = "Uklad: Straight";
		String result = "Uklad: " + (instance.pickSet());
		assertEquals(expectedResult, result);

		System.out.println("ustalUkladStrita test finished succesfully");
	}

	/*
	 * Test of ustalUkladTrojki method, of class Hand.
	 */
	public void testUstalUKladTrojki() {
		System.out.println("ustalUkladTrojki test begins");

		Card krol = fabrykaKartyKier(Rank.king);
		Card krol_2 = fabrykaKartyPik(Rank.king);
		Card f4 = fabrykaKartyKier(Rank.r4);
		Card f5 = fabrykaKartyPik(Rank.r5);
		Card krol_3 = fabrykaKartyTrefl(Rank.king);

		ArrayList<Card> karty = dodajKartyDoListy(krol, krol_2, f4, f5, krol_3);

		Hand instance = new Hand(karty);

		String expectedResult = "Uklad: Three_Of_A_Kind";
		String result = "Uklad: " + (instance.pickSet());
		assertEquals(expectedResult, result);

		System.out.println("ustalUkladTrojki test finished succesfully");
	}

	/*
	 * Test of ustalUkladPary method, of class Hand.
	 */
	public void testUstalUKladPary() {
		System.out.println("ustalUkladPary test begins");

		Card f2 = fabrykaKartyPik(Rank.r2);
		Card f2_2 = fabrykaKartyKier(Rank.r2);
		Card f4 = fabrykaKartyPik(Rank.r4);
		Card f5 = fabrykaKartyPik(Rank.r5);
		Card f6 = fabrykaKartyKier(Rank.r6);

		ArrayList<Card> karty = dodajKartyDoListy(f2, f2_2, f4, f5, f6);

		Hand instance = new Hand(karty);

		String expectedResult = "Uklad: A_Pair";
		String result = "Uklad: " + (instance.pickSet());
		assertEquals(expectedResult, result);

		System.out.println("ustalUkladPary test finished succesfully");
	}

	/*
	 * Test of ustalUkladDwochPar method, of class Hand.
	 */
	public void testUstalUKladDwochPar() {
		System.out.println("ustalUkladDwochPar test begins");

		Card f2 = fabrykaKartyTrefl(Rank.r2);
		Card f2_2 = fabrykaKartyPik(Rank.r2);
		Card f4 = fabrykaKartyPik(Rank.r4);
		Card f9 = fabrykaKartyKaro(Rank.r9);
		Card f9_2 = fabrykaKartyKier(Rank.r9);

		ArrayList<Card> karty = dodajKartyDoListy(f2, f2_2, f4, f9, f9_2);

		Hand instance = new Hand(karty);

		String expectedResult = "Uklad: Two_Pairs";
		String result = "Uklad: " + (instance.pickSet());
		assertEquals(expectedResult, result);

		System.out.println("ustalUkladDwochPar test finished succesfully");
	}

	/*
	 * Test of ustalUkladNajwyzszejKarty method, of class Hand.
	 */
	public void testUstalUKladNajwyzszejKarty() {
		System.out.println("ustalUkladNajwyzszejKarty test begins");

		Card f5 = fabrykaKartyTrefl(Rank.r5);
		Card f9 = fabrykaKartyPik(Rank.r9);
		Card f4 = fabrykaKartyKaro(Rank.r4);
		Card f7 = fabrykaKartyPik(Rank.r7);
		Card as = fabrykaKartyKier(Rank.ace);

		ArrayList<Card> karty = dodajKartyDoListy(f5, f9, f4, f7, as);

		Hand instance = new Hand(karty);

		String expectedResult = "Uklad: High_Card";
		String result = "Uklad: " + (instance.pickSet());
		assertEquals(expectedResult, result);

		System.out
				.println("ustalUkladNajwyzszejKarty test finished succesfully");
	}

	/*
	 * Random test of class Hand.
	 */
	public void testRandom() {
		System.out.println("testRandom test begins");

		Card dama_1 = fabrykaKartyPik(Rank.queen);
		Card dama_2 = fabrykaKartyPik(Rank.queen);
		Card as_1 = fabrykaKartyPik(Rank.ace);
		Card krol_1 = fabrykaKartyPik(Rank.king);
		Card f2 = fabrykaKartyPik(Rank.r2);

		Card f3 = fabrykaKartyTrefl(Rank.r3);
		Card dama_3 = fabrykaKartyTrefl(Rank.queen);
		Card dama_4 = fabrykaKartyTrefl(Rank.queen);
		Card krol_2 = fabrykaKartyTrefl(Rank.king);
		Card as_2 = fabrykaKartyTrefl(Rank.ace);

		ArrayList<Card> karty = dodajKartyDoListy(dama_1, dama_2, as_1, krol_1,
				f2);
		ArrayList<Card> kartyPrzeciwnika = dodajKartyDoListy(dama_3, dama_4,
				krol_2, as_2, f3);

		Hand instance = new Hand(karty);
		Hand drugaReka = new Hand(kartyPrzeciwnika);
		assertTrue((instance.compareTo(drugaReka) < 0));

	}

	/*
	 * Test of usunKarty method, of class Hand.
	 */
	public void testUsunKarty() {
		System.out.println("usunKarty test begins");

		Card f3 = fabrykaKartyPik(Rank.r3);
		Card f3_2 = fabrykaKartyPik(Rank.r3);
		Card dama = fabrykaKartyPik(Rank.queen);
		Card as = fabrykaKartyKier(Rank.ace);
		Card as_2 = fabrykaKartyKier(Rank.ace);
		ArrayList<Card> instance = dodajKartyDoListy(f3, f3_2, dama, as, as_2);
		ArrayList<Card> kartyDoUsuniecia = dodajKartyDoListy(f3, f3_2, dama,
				as, as_2);
		ArrayList<Card> expectedValue = dodajKartyDoListy();

		Hand reka = new Hand(instance);
		reka.delCards(kartyDoUsuniecia);
		assertEquals(expectedValue, instance);

		System.out.println("usunKarty test finished successfully");

	}

	public static Card fabrykaKartyPik(Rank f) {
		return new Card(f, Colour.spades);
	}

	public static Card fabrykaKartyKier(Rank f) {
		return new Card(f, Colour.hearts);
	}

	public static Card fabrykaKartyKaro(Rank f) {
		return new Card(f, Colour.diamonds);
	}

	public static Card fabrykaKartyTrefl(Rank f) {
		return new Card(f, Colour.clubs);
	}

	public static ArrayList<Card> dodajKartyDoListy(Card... karty) {
		ArrayList<Card> listaKart = new ArrayList<>();
		for (Card k : karty)
			listaKart.add(k);

		return listaKart;
	}
}
